<template>
  <div class="container">
    <div class="left">
      <div class="content" v-for="(item, index) in tableData" :key="index">
        <div class="title">
          {{ item.month }}
        </div>
        <div
          class="item"
          v-for="(item, index) in item.articles"
          :key="index"
          @click="toDetail(item)"
        >
          <div class="item_left">
            <img :src="item.titleImage" alt="" />
          </div>
          <div class="item_right">
            <div>{{ item.title }}</div>
            <p>
              <img src="@/assets/icon/time.png" alt="" />
              <span>{{ item.createTime }}</span>
            </p>
          </div>
        </div>
      </div>
      <div class="left_page">
        <Page-com
          :pages="pages"
          :pageSize="pageSize"
          :pageNumber="pageNumber"
          @back="currentIndex"
        ></Page-com>
      </div>
    </div>
    <div class="right">
      <div class="right_1">
        <Ha-com></Ha-com>
      </div>
    </div>
  </div>
</template>

<script>
import HaCom from "@/components/HaCom.vue";
// import TagCom from "@/components/TagCom.vue";
// import TypeCom from "@/components/TypeCom.vue";

import PageCom from "@/components/PageCom.vue";
export default {
  data() {
    return {
      title: "",
      tableData: "",
      //当前页
      currentInd: 1,
      //传递的参数
      pageSize: 10,
      pageNumber: null,
      pages: [],
    };
  },
  components: {
    HaCom,
    // TypeCom,
    // TagCom,
    PageCom,
  },
  methods: {
    toDetail(item) {
      this.$router.push({
        path: "/home/detail",
        query: {
          id: item.id,
        },
      });
    },
    toIncludeTag(item) {
      this.$router.push(
        {
          path: "/home/includetag",
          query: item,
        },
        () => {},
        () => {}
      );
    },
    getData() {
      this.$axios
        .post("api/archive/list", {
          current: this.currentInd,
          size: this.pageSize,
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data;
          this.pageNumber = res.current;
          this.pageSize = res.size;
          this.pages = [];
          this.title = res.data[0].month;
          for (let i = 0; i < res.pages; i++) {
            this.pages.push(i + 1);
          }
        });
    },
    currentIndex(val) {
      // console.log(val,'父组件val')
      this.currentInd = val;
      this.getData();
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: space-around;
  .left {
    width: 960px;
    background-color: #fff;
    border-radius: 10px;
    border: #ddd 2px solid;
    padding: 10px;
    .title {
      font-weight: bold;
      font-size: 18px;
      text-align: left;
    }
    .content {
      .item:hover {
        background-color: #eee;
        cursor: pointer;
      }
      .item {
        display: flex;
        flex-direction: row;
        border-bottom: 1px solid #ddd;
        padding: 10px;
        .item_left {
          margin-right: 10px;
          img {
            width: 96px;
            height: 48px;
            border-radius: 10px;
          }
        }
        .item_right {
          text-align: left;
          div {
            margin-bottom: 8px;
          }
          P {
            img {
              width: 20px;
              vertical-align: middle;
            }
            span {
              color: #aaa;
              font-size: 12px;
            }
          }
        }
      }
    }
    .left_page{
      width: 60%;
    }
  }
  .right {
    width: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    .right_1 {
      padding: 10px;
      background-color: #fff;
      width: 80%;
      height: 200px;
      border: #ddd solid 1px;
      border-radius: 10px;
    }
    .right_2 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
    .right_3 {
      padding: 10px;
      background-color: #fff;
      border-radius: 10px;
      width: 80%;
      border: #ddd solid 1px;
    }
  }
}
</style>